package com.xiaohui.user.thread;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description: 线程池配置示例
 */
@Configuration
public class ThreadPoolConfig {

//    @Autowired
//    private ThreadPoolExecutorBuilder threadPoolExecutorBuilder;

    @Bean(name = "mailThreadPool")
    public ThreadPoolExecutor getMailThreadPool() {
        ThreadFactory threadFactory = new CustomNameThreadFactory("mail");
        return new ThreadPoolExecutor(20,
                240,
                5,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue(40),
                threadFactory,
                new ThreadPoolExecutor.CallerRunsPolicy());
    }


//    @Bean(name = "testThreadPool")
//    public ThreadPoolTaskExecutor getThreadPoolTaskExecutor() {
//        return threadPoolExecutorBuilder.build(
//                new ThreadPoolExecutorProperty()
//                        .setCorePoolSize(20)
//                        .setQueueCapacity(100)
//                        .setMaxPoolSize(40)
//                        .setThreadName("testThreadPool"));
//    }

}
